#version 330 core

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aCol;
layout (location = 2) in vec2 aTexCoord;

out vec3 oCol;
out vec3 oPos;
out vec2 oTexCoord;

uniform float uW;
uniform float uH;

uniform float uTime;

mat3 rotate(float theta) {
    float cos = cos(theta);
    float sin = sin(theta);

    vec3 row1 = vec3(cos, -sin, 0.0);
    vec3 row2 = vec3(sin, cos, 0.0);
    vec3 row3 = vec3(0.0, 0.0, 1.0);

    return mat3(row1, row2, row3);
}

void main() {

    vec3 pos = aPos;

    float r = uW / uH;

    if (uW < uH) {
        pos.x *= r;
    } else {
        pos.y *= r;
    }

    mat3 m = rotate(uTime);

    gl_Position = vec4(m * pos, 1.0);
    oCol = aCol;
    oPos =  pos;
    oTexCoord = aTexCoord;
}
